package com.spark.mooc.ch5_rdd.part01_RDDBasics

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @description:
 * @time: 2020/11/26 23:33
 * @author: lhy
 */
object WordCount {
    def main(args: Array[String]): Unit = {
        val conf: SparkConf = new SparkConf().setAppName("WordCount").setMaster("local")
        val sc = new SparkContext(conf)
        val lines: RDD[String] = sc.textFile("data.txt/this.txt")
        val wordCount: RDD[(String, Int)] = lines.flatMap(_.split(" "))
                             .map((_,1))
                             .reduceByKey(_+_)
        wordCount.collect()
        wordCount.foreach(println)
    }
}
